package com.example.demo.controller;

import com.example.demo.dto.ReciteDTO;
import com.example.demo.dto.ReciteDashboardDTO;
import com.example.demo.dto.ReciteNumDTO;
import com.example.demo.dto.ReciteTimeDTO;
import com.example.demo.entity.Poetry;
import com.example.demo.param.ReciteData;
import com.example.demo.param.ReciteParam;
import com.example.demo.service.ReciteService;
import com.example.demo.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/recite")
public class ReciteController {

    @Resource
    private ReciteService reciteService;

    /*背诗页面上半部分*/
    @PostMapping("/count")
    @ResponseBody
    public Result getReciteCount(@RequestBody ReciteParam reciteParam){
        ReciteDTO reciteCount = reciteService.getReciteCount(reciteParam);
        return Result.ok().data("reciteCount", reciteCount);
    }

    /*统计页面*/
    @GetMapping("/dashboard")
    @ResponseBody
    public Result getDashBoard(Long userId){
        ReciteDashboardDTO reciteDashboardDTO = reciteService.getReciteDashBoard(userId);
        return Result.ok().data("reciteDashboardDTO", reciteDashboardDTO);
    }

    /*检查按钮*/
    @GetMapping("/nextPoetry")
    @ResponseBody
    public Result getNextPoetry(Integer authorId,Integer count){
        Poetry poetry = reciteService.getNextPoetry(authorId,count);
        return Result.ok().data("poetry", poetry);
    }

    /*结束背诗按钮*/
    @PostMapping("/addCount")
    @ResponseBody
    public Result addReciteData(@RequestBody ReciteData reciteData){
        reciteService.addReciteData(reciteData);
        return Result.ok();
    }

    /*统计背诵时间*/
    @GetMapping("/reciteTimeRank")
    @ResponseBody
    public Result reciteTimeRank(){
        ReciteTimeDTO result = reciteService.getReciteTimeCount();
        return Result.ok().data("result",result);
    }

    /*统计背诵数量*/
    @GetMapping("/reciteNumRank")
    @ResponseBody
    public Result reciteNumRank(){
        ReciteNumDTO result = reciteService.getReciteNumRank();
        return Result.ok().data("result",result);
    }

}
